import {
  DefaultCrudRepository,
  juggler,
  BelongsToAccessor,
  repository,
} from '@loopback/repository';
import { Todo, TodoList } from '../models';
import { MysqlLocalDataSource } from '../datasources';
import { inject, Getter } from '@loopback/core';
import { TodoListRepository } from './todo-list.repository';

export class TodoRepository extends DefaultCrudRepository<Todo,
  typeof Todo.prototype.id> {

  public readonly todoList: BelongsToAccessor<TodoList,
    typeof Todo.prototype.id>;

  constructor(
    @inject('datasources.mysqlLocal') dataSource: MysqlLocalDataSource,
    @repository.getter('TodoListRepository')
    protected todoListRepositoryGetter: Getter<TodoListRepository>,
  ) {
    super(Todo, dataSource);

    this.todoList = this.createBelongsToAccessorFor(
      'todoList',
      todoListRepositoryGetter,
    );
  }
}
